import { Schema, Prop, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
import { md5 } from 'src/util/auth';
export type UserDocument = User & Document;

@Schema()
export class User {
    @Prop({ required: true,unique:true })
    account: string;

    @Prop({ required: true ,unique:true})
    email: string;

    @Prop({
        required: true,
        select: false,
        set: (val: string) => {
            return md5(val);
        },
    })
    password: string;

    @Prop({ required: true ,unique:true})
    phone: string;

    @Prop({ required: false })
    nickname: string;

    @Prop({ required: false ,default:null})
    avater: string;

    @Prop({ required: false ,default:0})
    subscribecount: number;

    @Prop({default: new Date()})
    createtime:Date

    @Prop({default: new Date()})
    updatetime:Date
}

export const UserSchema = SchemaFactory.createForClass(User);